package com.eastday.util;
import java.io.IOException;
import java.util.List;


import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.Element;

import com.eastday.model.SysConfigModel;
import com.eastday.model.UrlConfigModel;
/**
 * 
 * @author dingxs
 *
 */
public class ParseConfigFactory {

	private static Document document;
	
	public static SysConfigModel sysConfigModel;
	public static UrlConfigModel urlConfigModel;
	public static String beanPath;
	
	public static void constructSysConfig() throws JDOMException,IOException
	{
		SAXBuilder builder = new SAXBuilder(false);
		document           = builder.build("./SysConfig.xml");
		sysConfigModel     = new SysConfigModel();
		sysConfigModel.buildSysConfig(document);
	}
	
	public static void constructUrlConfig() throws JDOMException,IOException
	{
		SAXBuilder builder = new SAXBuilder(false);
		document           = builder.build("./UrlConfig.xml");
		urlConfigModel     = new UrlConfigModel();
		urlConfigModel.buildUrlConfig(document);
	}
	
	public static String getBeanPath(String beanName) throws JDOMException,IOException
	{
		String classPath    = "";
		SAXBuilder builder  = new SAXBuilder(false);
		document            = builder.build("./BeanConfig.xml");
		Element root        = document.getRootElement();
		List<Element> beans = root.getChildren();
		for(int i = 0;i<beans.size();i++)
		{
			if(beans.get(i).getAttributeValue("name").equals(beanName))
			{
				Element classPathElement = beans.get(i).getChild("classpath");
				classPath                = classPathElement.getAttributeValue("value");
			}
		}
		return classPath;
		
	}
	
	
}
